<template>
  <div id='tmpl'>
  
    <!--1实现图片分类-->
    <div id="cate">
      <ul v-bind="{style:'width:'+ulwidth+'px'}">
        <li @click="getimg(0)">全部</li>
        <li v-for="(item,index) in cates" :key="index" @click="getimg(item.id)">{{item.title}} </li>
      </ul>
    </div>
  
    <!--2实现图片加载展示-->
  
    <div id="imglist">
      <ul>
        <li v-for="(item,index) in list" :key="index">
          <router-link v-bind="{to:'/photo/photoinfo/'+item.id}">
            <img v-lazy='item.img_url'>
            <div id="desc">
              <h5 v-text="item.title"></h5>
              <p v-text="item.zhaiyao"></p>
            </div>
          </router-link>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
import common from '../../kits/common.js';
import { Toast } from 'mint-ui'
export default {
  name: "component_name",
  data() {
    return {
      ulwidth: 375,
      cates: [],//存放图片数据的位置
      list: []
    };
  },
  created() {
    //调用图片分类信息
    this.getcates();

    //调用图片

    var all = 0;
    this.getimg(all);
  },
  methods: {

    //获取图片展示数据
    getimg(cateid) {

      cateid = cateid || 0;
      var url = common.apidomain + "/api/getimages/" + cateid;

      this.$http.get(url).then(function (res) {
        if (res.body.status != 0) {
          Toast(res.body.message);
          return;
        }
        this.list = res.body.message;

      })

    },


    //获取图片分类数据
    getcates() {
      var url = common.apidomain + '/api/getimgcategory';
      this.$http.get(url).then(function (res) {

        if (res.body.status != 0) {
          Toast(res.body.message);
          return;
        }
        this.cates = res.body.message;
        var w = 67;
        var count = res.body.message.length + 1;

        this.ulwidth = w * count;

      })

    }
  }

}
</script>
<style lang="css" scoped>
#cate {
  width: 375px;
  max-width: 375px;
  overflow-x: auto;
}

#cate ul {
  margin: 0px;
  padding-left: 10px;
}

#cate li {
  cursor: pointer;
  list-style: none;
  display: inline-block;
  font-size: 14px;
  color: #0094ff;
  padding: 6px;
}


/*图片样式*/

#imglist li {
  list-style: none;
  position: relative;
}

#imglist ul {
  padding-left: 0px;
}

#imglist img {

  width: 100%;
  height: 300px;
}

#desc {
  width: 100%;
  background-color: rgba(0, 0, 0, 0.25);
  position: absolute;
  bottom: 2px;
  left: 0px;
}

#desc h5 {
  color: #ffffff;
  font-weight: bold;
}

#desc p {
  color: #ffffff;
}

image[lazy=loading] {
  width: 40px;
  height: 300px;
  margin: auto;
}
</style>